package br.roove.bomotivo.ui;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.roove.bomotivo.model.Item;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

public class CustomArrayAdapterPhotosEvent extends ArrayAdapter<Item>{
	
	Context context;

	public CustomArrayAdapterPhotosEvent(Context context, int textViewResourceId,
			List<Item> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
	}
	
	private class ViewHolder {
		ImageView fotoevento;
		TextView evento;
		TextView data;
		TextView qtd_fotos;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		Item item = new Item();
		item = getItem(position);
		
		LayoutInflater minflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null){
			convertView = minflater.inflate(R.layout.simple_list_event_fotos, null);
			holder = new ViewHolder();
			holder.evento = (TextView)convertView.findViewById(R.id.nome_evento_foto);
			holder.data = (TextView)convertView.findViewById(R.id.data_simple_item_foto_evento);
			holder.qtd_fotos = (TextView)convertView.findViewById(R.id.numerofotos_simple_item_foto_evento);
			holder.fotoevento = (ImageView)convertView.findViewById(R.id.imageview_simple_item_foto_evento);
			convertView.setTag(holder);
			
			holder.data.setText(item.getData());
			holder.evento.setText(item.getEvento());
			holder.qtd_fotos.setText(Integer.toString(item.getImagen()) + " fotos");
			UrlImageViewHelper uHelper = new UrlImageViewHelper();
			if (item.getURL_foto_lista() != null){
			uHelper.setUrlDrawable(holder.fotoevento, item.getURL_foto_lista());
			}
			return convertView;
			
		}else{
			
			holder = (ViewHolder)convertView.getTag();
			
			holder.data.setText(item.getData());
			holder.evento.setText(item.getEvento());
			holder.qtd_fotos.setText(item.getImagen() + " fotos");
			UrlImageViewHelper uHelper = new UrlImageViewHelper();
			uHelper.setUrlDrawable(holder.fotoevento, item.getURL_foto_lista());
			
			return convertView;
		}
	}

}
